//
//  LYMineFollowTeacherViewController.m
//  artist
//
//  Created by Jay_Apple on 16/5/8.
//  Copyright © 2016年 viviyoo. All rights reserved.
//

#import "LYMineFollowTeacherViewController.h"
#import "LYTeacherCell.h"
#import "LYTeacherWebViewController.h"


@interface LYMineFollowTeacherViewController ()<UITableViewDataSource, UITableViewDelegate, LYTeacherCellDelegate>

@property (nonatomic, strong) NSArray *models;


@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation LYMineFollowTeacherViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadTeacherData];
}

#pragma mark - 网络请求
/**
 *  老师数据
 */
- (void)loadTeacherData{
    
    [MBProgressHUD showMessage:nil];
    
    
    [LYRequestTool getMyFollowListWithToken:LYToken role_id:LYRoleTypeTeacher success:^(NSArray<LYPersonalInfo *> *models) {
        [MBProgressHUD hideHUD];
        self.models = models;
        [self.tableView reloadData];
        
    } failure:^(NSString *code, NSString *message) {
        [MBProgressHUD hideHUD];
    }];
    
}

/**
 *  取消关注
 */
- (void)cancelFollowWithUserID:(NSString *)userID{
    [LYRequestTool cancelfollowWithToken:LYToken to_user_id:userID success:^{
        [self loadTeacherData];
        
    } failure:^(NSString *code, NSString *message) {
    }];
    
}

#pragma mark - tableviewDataSource


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.models.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellID = @"LYTeacherCell";
    
    LYTeacherCell *cell = [LYTeacherCell cellWithTableView:tableView andIndetifier:cellID];
    
    LYPersonalInfo *model = self.models[indexPath.section];
    model.showCancelFollowBtn = YES;
    cell.delegate = self;
    cell.model = model;
    
    return cell;
}

#pragma mark - tableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        return 0.1;
    }else{
        return 5;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 90;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LYPersonalInfo *info = self.models[indexPath.section];
    LYTeacherWebViewController *teaWebVC = [LYTeacherWebViewController teaWebVCWithID:info.user_id];
    [self.navigationController pushViewController:teaWebVC animated:YES];
    
}

#pragma mark - cellDelegate
- (void)cellCancelBtnOnclick:(LYTeacherCell *)cell{
    
    LYPersonalInfo *model = cell.model;
    [self cancelFollowWithUserID:model.user_id];
    
}




@end
